# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-facets
pkgver=3.1.0
pkgrel=2
pkgdesc='Premiere collection of general purpose method extensions and standard additions for the Ruby programming language'
arch=(any)
url='https://github.com/rubyworks/facets'
license=(BSD)
depends=(ruby)
checkdepends=(ruby-lemon ruby-qed ruby-rake ruby-rubytest-cli ruby-simplecov)
options=(!emptydirs)
source=(https://github.com/rubyworks/facets/archive/$pkgver/$pkgname-$pkgver.tar.gz)
sha256sums=('a432b57dd3999fd83b239d675cc97f28c626e1b2d1d91702de4fbaf951ae1fad')

build() {
  local _gemdir="$(gem env gemdir)"
  cd facets-$pkgver
  gem build facets.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    facets-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd facets-$pkgver
  # Gem is very old and unmaintained, many test failures with new Ruby.
  # Avoid using it!
  GEM_HOME="tmp_install/$_gemdir" rake || echo "Tests failed"
}

package() {
  cd facets-$pkgver
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 LICENSE.txt -t "$pkgdir"/usr/share/licenses/$pkgname/
}
